package com.dingzhen.entity;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.Aggregations;

import java.util.List;

public class SearchScrollHits<T> {
    private String scrollId;
    private List<T> hits;
    private SearchHits searchHits;

    public SearchScrollHits(SearchResponse searchResponse) {
        this(searchResponse.getHits());
        this.searchResponse = searchResponse;
        this.scrollId = searchResponse.getScrollId();
    }

    private SearchResponse searchResponse;

    public SearchScrollHits(SearchHits searchHits) {
        this.searchHits = searchHits;
    }

    public String getScrollId() {
        return scrollId;
    }

    public void setScrollId(String scrollId) {
        this.scrollId = scrollId;
    }

    public List<T> getHits() {
        return hits;
    }

    public void setHits(List<T> hits) {
        this.hits = hits;
    }

    public SearchHits getSearchHits() {
        return this.searchHits;
    }

    public void setSearchHits(SearchHits searchHits) {
        this.searchHits = searchHits;
    }

    public long getTotalHits() {
        return searchHits.getTotalHits().value;
    }

    public SearchResponse getSearchResponse() {
        return searchResponse;
    }

    public void setSearchResponse(SearchResponse searchResponse) {
        this.searchResponse = searchResponse;
    }

    public Aggregations getAggregations() {
        return this.searchResponse.getAggregations();
    }

}